<template>
    <view>
        <u--form labelWidth="100" labelAlign="center" :model="refund" :rules="rules" ref="uForm">
            <u-form-item label="客户退货原因" prop="son" borderBottom ref="item1">
                <u--input v-model="refund.son" border="none" disabled></u--input>
            </u-form-item>


            <u-form-item label="退货状态" prop="status" borderBottom ref="item1">
                <u--input v-model="refund.status" disabled border="none"></u--input>
                <u-icon slot="right" name="arrow-right"></u-icon>
            </u-form-item>

            <u-form-item label="是否同意退货" prop="auth" borderBottom @click="showAuth = true" ref="item1">
                <u--input v-model="refund.auth" disabled disabledColor="#ffffff" placeholder="请选择"
                    border="none"></u--input>
                <u-icon slot="right" name="arrow-right"></u-icon>
            </u-form-item>

            <u-form-item label="审核原因" prop="text" borderBottom ref="item1">
                <u--textarea v-model="refund.text" placeholder="请输入内容"></u--textarea>
            </u-form-item>
        </u--form>

        <u-action-sheet :show="showAuth" :actions="actions" title="请选择" @close="showAuth = false" @select="authSelect">
        </u-action-sheet>

        <u-button type="primary" @click="onSubmit">提交</u-button>
        <u-toast ref="uToast"></u-toast>

    </view>
</template>

<script>

export default {
    data() {
        return {
            LoginAdmin: {},
            refund: {
                son: "",
                status: "",
                auth: "",
                text: "",
                authid: 0,
            },
            id: 0,
            // 验证规则
            rules: {
                son: [
                    {
                        required: true,
                        message: '请输入客户退货原因',
                        trigger: ['change', 'blur'],
                    }
                ],
                status: [
                    {
                        required: true,
                        message: '请输入退货状态',
                        trigger: ['change', 'blur'],
                    }
                ],
                auth: [
                    {
                        required: true,
                        message: '请输入是否同意退货',
                        trigger: ['change', 'blur'],
                    }
                ],
                text: [
                    {
                        required: true,
                        message: '请输入审核原因',
                        trigger: ['change', 'blur'],
                    }
                ]
            },
            showAuth: false,
            actions: [
                {
                    name: '同意退货',
                    value: 1
                },
                {
                    name: '不同意退货',
                    value: 0
                }
            ],

            switchVal: false,
            radio: "",
        };
    },
    methods: {
        // 查询该订单数据
        async getList() {
            let data = {
                adminid: this.LoginAdmin.id,
                id: this.id
            }
            let res = await this.$u.api.manage.getRefund(data);
            if (res.code == 1 && res) {
                this.refund.son = res.data.refundreason
                this.refund.status = res.data.status_text
            }

        },
        authSelect(e) {
            this.refund.auth = e.name;
            this.refund.authid = e.value;
            this.showAuth = false;
        },
        onSubmit() {
            this.$refs.uForm.validate().then(async () => {
                let data = {
                    adminid: this.LoginAdmin.id,
                    id: this.id,
                    // 是否同意退货状态
                    auth: this.refund.authid,
                    text: this.refund.text
                }
                console.log(data);
                let result = await this.$u.api.manage.productRef(data);

                if (result.code == 1 && result) {
                    this.$refs.uToast.show({
                        type: "success",
                        message: result.msg,
                        complete: () => {
                            this.$u.route('/pages/manage/productorder/index');
                        },
                    });
                } else {
                    this.$refs.uToast.show({
                        type: "error",
                        message: result.msg,
                    })
                }

            }).catch((err) => {
                console.log(err);
            })
        }
    },
    onLoad(options) {
        this.LoginAdmin = uni.getStorageSync("admin") ?? {};
        this.id = options.id;
        this.getList();
    }
}
</script>